﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master_form.master" AutoEventWireup="true" CodeFile="dang_ky.aspx.cs" Inherits="App_Form_DanhMuc_giuong_nam" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript" src="../../resources/javascript/CheckColumn.js"></script>
    <script type="text/javascript" src="../../js/plugin/CellEditing.js"></script>
    <style type="text/css">
        .x-form-clear {
            background-image: url('../../resources/themes/images/default/form/search-trigger.gif');
            background-position: 0 0;
            width: 17px;
            height: 22px;
            border-bottom: 1px solid #b5b8c8;
            cursor: pointer;
            cursor: hand;
            overflow: hidden;
        }
    </style>
    <script type="text/javascript">

        Ext.Loader.setConfig({
            enabled: true
        });
        Ext.Loader.setPath('Ext.ux', '../ux');


        Ext.require([
            'Ext.selection.CellModel',
             'Ext.grid.*',
              'Ext.data.*',
              'Ext.util.*',
              'Ext.state.*',
              'Ext.form.*',
              'Ext.grid.Panel',
            'Ext.ux.CheckColumn'
        ]);


        Ext.onReady(function () {

            Ext.QuickTips.init();

            Ext.define('Ext.ux.CustomTrigger', {
                extend: 'Ext.form.field.Trigger',
                alias: 'widget.customtrigger',
                // override onTriggerClick
                initComponent: function () {
                    var me = this;

                    me.triggerCls = 'x-form-clear'; // native ExtJS class & icon

                    me.callParent(arguments);
                },
                onTriggerClick: function () {
                    //Mo cua so
                    var window = Ext.create('Ext.window.Window', {
                        title: 'Hello',
                        height: 300,
                        width: 400,
                        buttons: [
                            {
                                text: 'Chọn',
                                handler: function () {
                                    var records = Ext.getCmp("tm_sv").getSelectionModel().getSelection();
                                    if (records[0]) {
                                        var b_grid = records[0].get("sv_ma");
                                        Ext.getCmp("ma_sv").setValue(b_grid);
                                        window.close();
                                    }                                   
                                }
                            }
                        ],
                        layout: {
                            type: 'table',
                            columns: 1
                        },
                        fieldDefaults: {
                            labelAlign: 'left',
                            msgTarget: 'side'
                        },
                        items: [
                           {
                               margin: '0 0 0 0',
                               xtype: 'fieldset',
                               title: 'Thông tin tim',
                               defaults: {
                                   width: 370,
                                   labelWidth: 90
                               },
                               defaultType: 'textfield',
                               items: [
                               {
                                   xtype: 'fieldcontainer',
                                   fieldLabel: 'Mã sinh viên',
                                   combineErrors: false,
                                   layout: {
                                       type: 'hbox',
                                       defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                                   },
                                   defaults: {
                                       hideLabel: true
                                   },
                                   items: [
                                   { xtype: 'textfield', fieldLabel: 'sv_ma', width: 250, name: 'sv_ma', id:'sv_ma', width: 140, allowBlank: true },
                                   {
                                       name: 'tim_kiem',
                                       xtype: 'button',
                                       width: 90,
                                       icon: '../../shared/icons/fam/refesh.png',
                                       text: 'Tìm',
                                       handler: function () {
                                           var b_ma = Ext.getCmp("sv_ma").getValue();
                                           DanhMuc.Fs_SINH_VIEN_TIM(b_ma, sinh_vien_tim_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                       }
                                   }
                                   ]
                               }]
                           },
                                {
                                    xtype: 'gridpanel',
                                    margin: '0 0 0 1',
                                    border: false,
                                    id: 'tm_sv',
                                    columns: [
                                        { id: 'svma', text: ' Mã SV', width: 50, flex: 1, sortable: true, dataIndex: 'sv_ma' },
                                        { id: 'svname', text: 'Tên sinh viên', width: 150, flex: 1, sortable: true, dataIndex: 'sv_ten' },
                                        { id: 'sv_lop', text: 'Lớp', width: 150, flex: 1, sortable: true, dataIndex: 'sv_lop' }
                                    ],
                                    store: null,
                                    listeners: {
                                        selectionchange: function (model, records) {
                                           
                                        }
                                    }
                                }]
                    }).show();
                }
            });

            var bd = Ext.getBody();

            var gridForm = Ext.create('Ext.form.Panel', {
                id: 'company-form',
                frame: true,
                bodyPadding: 5,
                layout: {
                    type: 'table',
                    columns: 2
                },
                fieldDefaults: {
                    labelAlign: 'left',
                    msgTarget: 'side'
                },

                items: [
                    {
                        columnWidth: '40%',
                        margin: '0 0 0 10',
                        xtype: 'fieldset',
                        title: 'Thông tin chính',
                        defaults: {
                            width: 350,
                            labelWidth: 90
                        },
                        defaultType: 'textfield',
                        items: [{
                            fieldLabel: 'Mã',
                            xtype: 'hidden',
                            id: 'id',
                            name: 'id'
                        },
                        {
                            fieldLabel: 'Mã',
                            xtype: 'hidden',
                            id: 'ten_sv',
                            name: 'ten_sv'
                        },
                        {
                            xtype: 'combo',
                            value: '',
                            emptyText: 'Chọn tên nhà',
                            triggerAction: 'all',
                            forceSelection: true,
                            editable: false,
                            fieldLabel: 'Nhà',
                            id: 'nha',
                            name: 'nha',
                            displayField: 'tenNha',
                            valueField: 'id',
                            queryMode: 'local',
                            store: null,
                            listeners: {
                                select: function (combo, record, index) {
                                    if (record.length > 0) {
                                        var id_nha = record[0].get('id');
                                        //Goi service
                                        DanhMuc.Fs_PHONG_LKE(id_nha, phong_nha_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                    }
                                }
                            }
                        },
                        {
                            xtype: 'combo',
                            value: '',
                            emptyText: 'Chọn tên phòng',
                            triggerAction: 'all',
                            forceSelection: true,
                            editable: false,
                            fieldLabel: 'Phòng',
                            id: 'chonphong',
                            name: 'phong',
                            displayField: 'Ten',
                            valueField: 'id',
                            queryMode: 'local',
                            store: null,
                            listeners: {
                                select: function (combo, record, index) {
                                    if (record.length > 0) {
                                        var id_nha = record[0].get('id');
                                        //Goi service
                                        DanhMuc.Fs_KT_DK_LK(id_nha, phong_dk_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                    }
                                }
                            }
                        }
                        ,
                        {
                            xtype: 'customtrigger',
                            fieldLabel: 'Mã SV',
                            id: 'ma_sv',
                            name: 'ma_sv'
                        },
                        {
                            xtype: 'fieldcontainer',
                            combineErrors: true,
                            layout: {
                                type: 'hbox',
                                defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                            },
                            items: [
                                {
                                    name: 'add',
                                    xtype: 'button',
                                    width: 90,
                                    icon: '../../shared/icons/fam/add.gif',
                                    text: 'Thêm mới',
                                    handler: function () {
                                        var form = this.up('form').getForm();
                                        if (form.isValid()) {
                                            var b_ten = Ext.getCmp('chonphong').getValue();
                                            var b_ma_sv = Ext.getCmp('ma_sv').getValue();
                                            if (b_ten == "") { return alert("Chưa chọn phòng"); }
                                            if (b_ma_sv == "") { return alert("Chưa nhập sinh viên"); }

                                            var b_tinhdiem = Ext.getCmp('dk_phong');
                                            var a_gtriGrid = new Array();
                                            var i = 0;
                                            b_tinhdiem.getStore().each(function (record) {
                                                if (NVL(record.get("id")) != "") {
                                                    a_gtriGrid[i] = [record.get("id"), b_ma_sv, record.get("chon")];
                                                    i++;
                                                }
                                            });
                                            DanhMuc.Fs_PH_DK_NH(b_ten, b_ma_sv, a_gtriGrid, phong_dk_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    }
                                },
                                {
                                    name: 'moi',
                                    xtype: 'button',
                                    width: 90,
                                    icon: '../../shared/icons/fam/refesh.png',
                                    text: 'Mới',
                                    handler: function () {
                                        Ext.getCmp("ma_sv").setValue("");
                                    }
                                },
                                {
                                    name: 'xoa',
                                    xtype: 'button',
                                    width: 90,
                                    icon: '../../shared/icons/fam/delete.gif',
                                    text: 'Xóa',
                                    handler: function () {
                                        var c = confirm("Bạn có chắc chắn xóa không ?"); if (!c) return;
                                        var b_rd = Ext.getCmp("dk_phong").getSelectionModel().getSelection();
                                        if (!b_rd[0]) { return alert("Chưa chọn để xóa") };
                                        var b_ph = Ext.getCmp('chonphong').getValue();
                                        var b_id = b_rd[0].get("id");
                                        DanhMuc.Fs_PHONG_DK_XOA(b_id, b_ph, phong_dk_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                    }
                                }
                            ]
                        }
                        ]
                    },
                    {
                        columnWidth: '60%',
                        xtype: 'gridpanel',
                        margin: '0 0 0 1',
                        id: 'dk_phong',
                        store: null,
                        width: 400,
                        height: 400,
                        title: 'Danh sách giường',
                        plugins: Ext.create('Ext.grid.plugin.CellEditing', {
                            clicksToEdit: 1,
                            pluginId: 'rowEditing'
                        }),
                        emptyText: 'Không có bản nghi',
                        columns: [
                            { id: 'g', flex: 1, text: 'Mã', hidden: true, dataIndex: 'id' },
                            { id: 'nma_sv', flex: 1, text: 'ma_sv', hidden: true, dataIndex: 'ma_sv' },
                            { id: 'idPhonga', flex: 1, text: 'idPhong', hidden: true, dataIndex: 'idPhong' },
                            { id: 'ten_phong', text: 'Tên giường', width: 150, flex: 1, sortable: true, dataIndex: 'giuong' },
                            { id: 'svname', text: 'Tên sinh viên', width: 150, flex: 1, sortable: true, dataIndex: 'ten_sv' },
                            {
                                id: 'chonsv', text: 'Chọn', width: 100, flex: 1, sortable: true, dataIndex: 'chon',
                                editor: {
                                    xtype: 'combobox',
                                    typeAhead: true,
                                    width: 77,
                                    triggerAction: 'all',
                                    selectOnTab: true,
                                    store: [
                                        ['Đã đăng ký', 'Đã đăng ký'],
                                        ['Chưa đăng ký', 'Chưa đăng ký']
                                    ],
                                    lazyRender: true,
                                    listClass: 'x-combo-list-small'
                                }
                            }
                        ],
                        listeners: {
                            selectionchange: function (model, records) {
                                if (records[0]) {
                                   // this.up('form').getForm().loadRecord(records[0]);
                                }
                            },
                            'beforeedit': function (e, b) {
                                var b_edit = true;
                                if (e.value == "Đã đăng ký") {
                                    b_edit = false;
                                }
                                return b_edit;
                            },
                            'edit': function (e) {
                                this.isEditAllowed = false;
                            }
                        }
                    }
                ],
                renderTo: bd
            });
            DanhMuc.Fs_NHA_LKE(P_LOAD_TTCHUNG, P_LOI_CSDL, P_LOI_TGIAN);
        });

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">
        function P_LOAD_TTCHUNG(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var a_kq = b_kq.split('@');
                var b_chuoi2 = CH_JSON(a_kq[0]);
                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'tenNha'],
                    data: b_chuoi2
                });
                var c = Ext.getCmp('nha');
                c.bindStore(a_data2);
            }
        }
        function phong_nha_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b_chuoi2 = CH_JSON(b_kq);
                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'Ten'],
                    data: b_chuoi2
                });
                var c = Ext.getCmp('chonphong');
                c.bindStore(a_data2);
            }
        }
        function P_PHONG_XOA_KQ(b_kq) {
            phong_nha_P_KQ(b_kq);
            Ext.getCmp('id').setValue("");
        }
        function phong_dk_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b_chuoi2 = CH_JSON(b_kq);
                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'ma_sv', 'giuong', 'ten_sv', 'chon'],
                    data: b_chuoi2
                });
                var c = Ext.getCmp('dk_phong');
                c.bindStore(a_data2);
            }
        }
        function sinh_vien_tim_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b_chuoi2 = CH_JSON(b_kq);
                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ["sv_ma", "sv_ten", "sv_lop"],
                    data: b_chuoi2
                });
                var c = Ext.getCmp('tm_sv');
                c.bindStore(a_data2);
            }
        }
       
    </script>
</asp:Content>

